﻿<div class="datagrid-toolbar formToolBar">
    <a href="#" class="easyui-linkbutton" plain="true" onclick="save()" iconcls="iconfont iconfont-baocun">保存</a>
</div>
<div style="padding:2px;">
    <form method="post">
        <input id="Id" name="Id" type="hidden" />
        <table class="groupTable">
            <tr>
                <td style="width:15%">类全名:</td>
                <td style="width:35%">
                    <input id='EntityFullName' name='EntityFullName' class='easyui-mfbuttonedit' data-options="required:false,onButtonClick:entityFullNameSelect,onClearButtonClick:clearButtonClick" style='width:100%;' />
                </td>
                <td style="width:15%">
                    表名:
                </td>
                <td style="width:35%">
                    <input id="TableName" name="TableName" class="easyui-textbox" data-options="required:true" style=" width:100%" />
                </td>
            </tr>
            <tr>
                <td style="width:15%">编号:</td>
                <td style="width:35%">
                    <input id="Code" name="Code" class="easyui-textbox" data-options="required:true,onChange:onCodeChange" style="width:100%" />
                </td>
                <td style="width:15%">
                    名称:
                </td>
                <td style="width:35%">
                    <input id="Name" name="Name" class="easyui-textbox" style="width:100%" />
                </td>
            </tr>
            <tr>
                <td style="width:15%">数据库:</td>
                <td style="width:35%">
                    <input id="ModuleName" class="easyui-combobox" name="ModuleName"
                           data-options="required:true,valueField:'value',textField:'text',panelHeight:'auto',data:ModuleNames,onChange:dbNameValueChanged" style="width:100%" />
                </td>
                <td style="width:15%">
                    类别:
                </td>
                <td style="width:35%">
                    <input id="MainTypeFullId" name="MainTypeFullId" class="easyui-combobox" data-options="valueField:'value',textField:'text',panelHeight:'auto',editable:false" style="width:100%" />
                </td>
            </tr>
            <tr>
                <td style="width:15%">
                    流程实例名:
                </td>
                <td colspan="3" style="width:100%">
                    <div id="FlowInstNameExpression" name="FlowInstNameExpression" class="formFormulaEditor" placeholder="{FormData1}其中FormData为表单字段" style=""></div>
                </td>
            </tr>
            <tr>
                <td>备注:</td>
                <td colspan="3">
                    <input id="Remark" name="Remark" class="easyui-textbox" data-options="multiline:true,height:100" style="width:100%" />
                </td>
            </tr>
        </table>
    </form>
</div>

<script>
    var id = queryString('id');
    @Html.ModuleNames()

    $(function () {
        $('#FlowInstNameExpression').formFormulaEditor({
        });
    })

    var defineData = {};
    function SetData(d) {

    }

    function pageLoad() {
        //编辑
        if (id) {
            $("#Id").val(id);
            addAjaxParam("id", id);
            commitAjax("GetWorkFlowDef", {
                CallBack: function (data) {
                    if (data) {
                        $('#Code').textbox('setValue', data.Code);
                        $('#Name').textbox('setValue', data.Name);
                        $('#ModuleName').textbox('setValue', data.ModuleName);
                        $('#MainTypeFullId').textbox('setValue', data.MainTypeFullId);
                        $('#Remark').textbox('setValue', data.Remark);
                        $('#MainTypeFullId').combobox('setValue', data.MainTypeFullId);
                        $('#FlowInstNameExpression').formFormulaEditor('setValue', data.FlowInstNameExpression);
                        $('#FlowInstNameExpression').formFormulaEditor('setCode', data.Code);
                        checkFulNameSelect();
                    }
                }
            });
        }
    }

    function save() {
        var isValid = $('form').form('validate');
        if (!isValid) {
            msgBox('请检查所填数据!');
            return;
        }

        var formData = getFormData($('form'));
        addAjaxParam("formData", formData);
        commitAjax("SaveWorkFlowDef", {
            CallBack: function (data) {
                if (data) {
                    closeWindow(true);
                }
                else {
                    msgBox('操作失败');
                }
            }
        })
    }

    function onCodeChange(newValue, oldValue)
    {
        $('#FlowInstNameExpression').formFormulaEditor('setCode', newValue);
    }

    function entityFullNameSelect(e) {
        var url = "EntityList"
        var windowSettings = {};
        windowSettings.width = 600;
        windowSettings.height = 300;
        windowSettings.onDestroy = function (data) {
            if (data != 'close') {
                $('#EntityFullName').textbox('setValue', '');//先value
                $('#EntityFullName').textbox('setText', '');//先value

                $('#EntityFullName').textbox('setValue', data.EntityFullName);
                $('#ModuleName').combobox('setValue', data.ModuleName);
                $('#TableName').textbox('setValue', data.TableName);
                $('#Code').textbox('setValue', data.EntityFullName.replace(/[.]/g, "_"));
                dbNameValueChanged();
                checkFulNameSelect();
            }
        }
        openWindow(url, windowSettings);
    }

    function dbNameValueChanged() {
        var val = $('#ModuleName').combobox('getValue');
        $('#MainTypeFullId').combobox('clear');
        var url = '/AutoUI/ConfigUIDef/MainType/GetMainTypeList?ModuleName=' + val;
        $('#MainTypeFullId').combobox('reload', url);
    }

    function checkFulNameSelect() {
        var val = $('#EntityFullName').textbox('getValue');
        if (val && val != '') {
            $('#ModuleName').combobox('readonly', true);
            $('#TableName').textbox('readonly', true);
            $('#Code').textbox('readonly', true);
        }
        else {
            $('#ModuleName').combobox('readonly', false);
            $('#TableName').textbox('readonly', false);
            $('#Code').textbox('readonly', false);
        }
    }

    function clearButtonClick() {
        $('#ModuleName').combobox('setValue', '');
        $('#TableName').textbox('setValue', '');
        $('#Code').textbox('setValue', '');
        checkFulNameSelect();
    }
</script>
